انتقل إلى المحتوى الرئيسي

🍽 Restaurant Settings API Documentation

This document explains the purpose and structure of a restaurant settings system built using C# and FastEndpoints.


🏗 Code Structure and Explanation

1. AppSettings Class

The AppSettings class contains nested static classes to group related settings. Each field is of type Setting<T>, representing a configurable value (e.g., string, int, bool).

Example:

[Description("إسم المطعم")]
public static Setting<string> RestaurantName = new("RestaurantInfo.RestaurantName", "إسم المطعم");
  • Key: "RestaurantInfo.RestaurantName"
  • Default value: "إسم المطعم"
  • Arabic description: For display in a UI or frontend

Groups include:

  • RestaurantInfo
  • InvoiceAndKitchenInfo
  • InvoiceSettings

2. GetAllSettingsEndPoint API

This is a FastEndpoints API endpoint that returns all settings as a JSON list when GET /settings is called.

Process:

  1. Uses reflection to find all nested static classes inside AppSettings.

  2. For each class (e.g., RestaurantInfo), creates a GroupSettingsResponse:

    • GroupName: e.g. RestaurantInfo
    • displayText: Arabic description (e.g. "معلومات المطعم")
  3. For each field inside the group:

    • Reads static field via reflection
    • Extracts the DescriptionAttribute
    • Reads Setting<T>.Value
    • Detects the value type (e.g., string, int, enum)

Special Handling:

  • PrinterName:

    • Uses _printerService.GetPrintersAsync() to get available printers
    • Sets Type = "Enum" and populates Options with printer names
  • Enum values:

    • Uses reflection to get all enum members
    • Reads DescriptionAttribute for display purposes
    • Adds to Options list

Output:

Returns a list of GroupSettingsResponse objects, each containing a list of SettingResponse items.


3. Models

GroupSettingsResponse

public string GroupName;         // e.g. "InvoiceSettings"
public string displayText; // e.g. "اعدادات الفواتير"
public List<SettingResponse> Settings;

SettingResponse

public string Key;               // e.g. "PrinterName"
public string Value; // e.g. "Epson TM-T20"
public string Type; // "String", "Int32", "Enum", etc.
public string DisplayText; // Arabic description
public List<enumoptions>? Options; // Enum/Printer options if applicable

✅ Purpose

This settings API allows the frontend to dynamically load and display all restaurant settings with:

  • Grouping and Arabic labels for UI clarity
  • Enum support and runtime options (like printers)
  • Strong typing for each setting

🚀 Use Case

A frontend admin panel can call GET /settings to:

  • Display setting groups and items
  • Use metadata like display text and enums for building localized UIs